/*
 *
 * @ProjectName:    my_umi_app
 * @Package:
 * @ClassName:      today
 * @Description:    JSX文件
 * @Author:         SuPeiSen
 * @CreateDate:     2021/3/5 12:27 上午
 * @UpdateDate:     2021/3/5 12:27 上午
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */

import ProTable, { ProColumns } from '@ant-design/pro-table';
import { Button } from 'antd';
import { SortOrder } from 'antd/lib/table/interface';
import React from 'react';
import { GetStatisticsListApi } from '@/service/statistics_api';
import { StatisticsItemType } from '@/type/statistics_type';
import './style/today.less';
import { history } from '@@/core/history';

// 跳转到文章详情
const pushStatistics = (id: number, route: string) => {
  history.push({
    pathname: '/admin/blog_statistics/' + route,
    query: {
      id: id,
    },
  });
};
const columns: ProColumns<StatisticsItemType>[] = [
  {
    title: 'id',
    dataIndex: 'id',
    key: 'id',
    search: false,
    editable: false,
  },
  {
    title: '文章点击',
    dataIndex: 'today_article_num',
    search: false,
    render: (dom, item) => {
      return (
        <div style={{ display: 'flex' }}>
          <div className={'show_json_text'}>{item.today_article_num}</div>
          <Button
            onClick={() => pushStatistics(item.id, 'today_article_details')}
            style={{ margin: '0 1%' }}
            size={'small'}
            type="primary"
          >
            详情
          </Button>
        </div>
      );
    },
  },
  {
    title: '广告点击',
    dataIndex: 'today_ad_num',
    search: false,
    render: (dom, item) => {
      return (
        <div style={{ display: 'flex' }}>
          <div className={'show_json_text'}>{item.today_ad_num}</div>
          <Button
            onClick={() => pushStatistics(item.id, 'today_ad_details')}
            style={{ margin: '0 1%' }}
            size={'small'}
            type="primary"
          >
            详情
          </Button>
        </div>
      );
    },
  },
  {
    title: '添加时间',
    dataIndex: 'add_time',
  },
];

export default () => {
  const getShareUrlList = async (
    params: {
      pageSize?: number;
      current?: number;
      keyword?: string;
    },
    sort: {
      [key: string]: SortOrder;
    },
    filter: {
      [key: string]: React.ReactText[];
    },
  ) => {
    const model = await GetStatisticsListApi({
      page: params.current ?? 1,
      limit: params.pageSize ?? 10,
    });
    if (model.success) {
      return {
        success: true,
        data: model.data!.data.lists,
        total: model.data!.data.total,
      };
    }
    return {
      data: [],
      success: false,
    };
  };

  return (
    <ProTable<StatisticsItemType>
      columns={columns}
      rowKey="id"
      request={getShareUrlList}
      pagination={{ pageSize: 10 }}
    />
  );
};
